home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fhard101.zip / VHPREP.ASM < prev    next >
Assembly Source File  |  1990-07-17  |  20KB  |  745 lines

  1.  
  2.     title    Prepare VHARD floppies
  3.     subttl    Prologue
  4.     page    60,132
  5.  
  6. comment    {
  7.  
  8. ******************************************************************************
  9.  
  10. File VHPREP.ASM
  11.  
  12. Author:
  13.     Aaron L. Brenner
  14.  
  15.     BIX mail address albrenner
  16.     GEnie address A.BRENNER
  17.  
  18.     This program is hereby released to the public domain.
  19.  
  20. Purpose:
  21.     Prepare floppy diskettes for use with VHARD.
  22.  
  23.     This consists of the following:
  24.  
  25.     1) Format the floppies to 10 sectors per track, 40 tracks (resulting
  26.        in a capacity of 800K per diskette).
  27.     2) Write the VHARD boot sector to each disk containing, along with
  28.        boot code, a disk ID and number.
  29.     3) Write a DOS boot sector, 2 FATs, and root directory to the first
  30.        disk.
  31.  
  32.     All disk operations are performed through VHARDCTL, the character
  33.     device driver installed with VHARD.
  34.  
  35. Errorlevel returned:
  36.     0        All is well
  37.     1        VHARD.SYS is not installed
  38.  
  39. Revision history:
  40. 1.00    07/11/90    ALB    Created.
  41.  
  42. ******************************************************************************
  43.  
  44. endcomment {
  45.  
  46.     subttl    Included files
  47.     page
  48.  
  49.     include    dd_defs.inc
  50.     include    vhard.inc
  51.  
  52.     subttl    Program data and stack
  53.     page
  54.  
  55. vhprep_data    segment    para
  56.  
  57. ID_to_use    db    8 dup(' ')    ; ID to use for the diskettes
  58. disk_num    db    0ffh        ; Number for each diskette
  59. track_buf    db    512 * 10 dup(0)    ; Track buffer for reading and writing
  60. drive_num    db    0        ; The drive assigned to VHARD
  61. vhard_vnum    dw    0        ; Version of VHARD
  62. VHARD_BPB    DOS_BPB <>        ; BPB gotten from VHARD
  63.  
  64.         dw    81h        ; Pointer to our command tail
  65. our_PSP        dw    0        ; Our PSP segment
  66.  
  67. ;
  68. ; This block is used to pass commands to VHPREP
  69. ;
  70. command_blk    VH_CMD <>
  71.  
  72. vhctl_name    db    'VHARDCTL',0    ; Name of control driver for VHARD
  73. vhctl_handle    dw    0        ; Handle for VHARDCTL
  74. not_installed    db    13,10,'The VHARD driver is not installed.',13,10,'$'
  75. insert_disk    db    13,10,'Put a blank diskette in drive A:, then press'
  76.         db    ' a key $'
  77. label_disk    db    'Label this diskette $'
  78. disk_bad    db    7,13,10,'This diskette is unusable!',13,10,'$'
  79. crlf_str    db    13,10,'$'
  80.  
  81. err_prefix    db    7,'Error: $'
  82.  
  83. err0        db    'spurious error message$'
  84. err1        db    'drive/adapter failed or no disk in drive$'
  85. err2        db    'seek operation failed$'
  86. err3        db    'disk adapter failed$'
  87. err4        db    'CRC error$'
  88. err5        db    'attempt to DMA across segment boundary$'
  89. err6        db    'DMA overrun$'
  90. err7        db    'sector not found$'
  91. err8        db    'diskette is write-protected$'
  92. err9        db    'address mark not found$'
  93. err10        db    'invalid BIOS command$'
  94. err11        db    'internal command error$'
  95. err0ff        db    'unknown BIOS error code$'
  96.  
  97. error_msgs    dw    err0, err1, err2, err3, err4, err5, err6, err7, err8
  98.         dw    err9, err10, err11, err0, err0, err0ff
  99.  
  100. vhprep_data    ends
  101.  
  102.  
  103. vhprep_stack    segment    word    stack
  104.  
  105.     dw    256 dup(0)
  106.  
  107. vhprep_stack    ends
  108.  
  109.  
  110. ;*****************************************************************************
  111. ;
  112. ; This gets written to the actual boot sector of each diskette. As you can
  113. ; see, it just spits out a message, waits for a key, then tries to IPL again.
  114. ;
  115. ;*****************************************************************************
  116. boot_code_seg    segment    para
  117.  
  118. assume    cs:boot_code_seg, ds:boot_code_seg
  119.  
  120.     org    0
  121. boot_code    proc    near
  122.  
  123.     jmp    short boot_msg_disp    ; Jump to message display code
  124.     db    17 dup(?)        ; Place keeper for disk ID & number
  125. boot_msg_disp:
  126.     cld                ; Make sure of direction
  127.     call    do_display        ; Do the display
  128.     db    7,'This is NOT a bootable diskette!',13,10
  129.     db    'Put a different disk in the drive, and press a key to'
  130.     db    ' try again',13,10,0
  131. do_display:
  132.     pop    si            ; Point to the string to display
  133. ddsp_l1:
  134.     lods    byte ptr cs:[si]    ; Get a byte
  135.     or    al,al            ; End of string yet?
  136.     jz    ddsp_l2            ; Yep - just hang up now
  137.     mov    ah,14            ; BIOS "Write TTY" function
  138.     int    10h            ;
  139.     jmp    short ddsp_l1        ; Loop back for the rest
  140. ddsp_l2:
  141.     sub    ah,ah            ; Get a key
  142.     int    16h            ;
  143.     int    19h            ; Try to IPL again
  144.     jmp    $            ; Hang up now
  145.  
  146. boot_code_end    label    byte
  147.  
  148. boot_code    endp
  149.  
  150. boot_code_seg    ends
  151.  
  152.  
  153.     subttl    Start of program code
  154.     page
  155.  
  156. vhprep_code    segment
  157.  
  158. assume    cs:vhprep_code, ds:vhprep_data, es:vhprep_data, ss:vhprep_stack
  159.  
  160.  
  161. start    proc
  162.  
  163.     call    initialize        ; Set things up
  164.     call    do_prep            ; Do the preparation
  165.     call    terminate        ; Do program cleanup
  166.     mov    ax,4c00h        ;
  167.     int    21h            ;
  168.  
  169. start    endp
  170.  
  171.  
  172. ;*****************************************************************************
  173. ;
  174. ; Program initialization.
  175. ;
  176. ; Make sure the VHARDCTL driver is present, and get driver info from it.
  177. ;
  178. ;*****************************************************************************
  179. initialize    proc    near
  180.  
  181.     mov    ax,vhprep_data        ; Get our data segment
  182.     mov    ds,ax            ;
  183.     mov    our_PSP,es        ; Save our PSP segment
  184.     mov    es,ax            ;
  185.     mov    dx,offset vhctl_name    ; Try to open VHARDCTL, read/write
  186.     mov    ax,3d02h        ;
  187.     int    21h            ;
  188.     jnc    init_l1            ; If it opened, make sure it's a dev
  189. init_noway:
  190.     mov    dx,offset not_installed    ; Complain that it isn't there
  191.     mov    ah,9            ;
  192.     int    21h            ;
  193.     mov    ax,4c01h        ; Exit with errorlevel of 1
  194.     int    21h            ;
  195. init_l1:
  196.     mov    vhctl_handle,ax        ; Save the handle for other ops
  197.     mov    bx,ax            ; Get the handle for IOCTL call
  198.     mov    ax,4400h        ; Get info on this guy
  199.     int    21h            ;
  200.     test    dl,80h            ; Is this a device?
  201.     jz    init_noway        ; Nope - no way we're doing anything
  202.     mov    command_blk.VC_cmd_code,CMD_GETDATA
  203.     mov    word ptr command_blk.VC_buffer[0],offset drive_num
  204.     mov    word ptr command_blk.VC_buffer[2],ds
  205.     mov    ax,4403h        ; Get data from VHARDCTL
  206.     mov    dx,offset command_blk    ;
  207.     mov    cx,size VH_CMD        ;
  208.     int    21h            ;
  209.     call    get_cmdline_parms    ; Get a parameters from the cmd line
  210.     cmp    byte ptr ID_to_use[0],' '; Did they supply an ID?
  211.     jne    init_exit        ; Yep - don't change it
  212.     mov    ah,0            ; Get timer count from BIOS
  213.     int    1ah            ; Returns CX:DX
  214.     mov    ax,'HV'            ; Set up disk ID
  215.     mov    word ptr ID_to_use[0],ax;
  216.     mov    ax,cx            ; Use the time as part of the ID
  217.     mov    di,offset ID_to_use[2]    ;
  218.     call    store2digits        ;
  219.     mov    al,dh            ;
  220.     call    store2digits        ;
  221.     mov    al,dl            ;
  222.     call    store2digits        ;
  223. init_exit:
  224.     ret                ; Return to Main
  225.  
  226. initialize    endp
  227.  
  228.  
  229. ;*****************************************************************************
  230. ;
  231. ; Get any command line parameters
  232. ;
  233. ; The only parameters allowed are a disk ID and a disk number.
  234. ;
  235. ;*****************************************************************************
  236. get_cmdline_parms    proc    near
  237.  
  238.     push    es            ; Save it for this
  239.     les    si,dword ptr our_PSP[-2]; Point to the command tail
  240.     call    skip_spaces        ; Skip any whitespace
  241.     mov    cx,8            ; Max to copy
  242.     mov    di,offset ID_to_use    ;
  243. gcmp_l1:
  244.     lods    byte ptr es:[si]    ; Get a byte
  245.     cmp    al,' '            ; Whitespace?
  246.     je    gcmp_l3            ; Yep - stop copying
  247.     cmp    al,9            ;
  248.     je    gcmp_l3            ;
  249.     cmp    al,0dh            ; End of it?
  250.     je    gcmp_exit        ; Yep - exit
  251.     cmp    al,'a'            ; Lower case?
  252.     jb    gcmp_l2            ; No - never mind
  253.     cmp    al,'z'            ;
  254.     ja    gcmp_l2            ;
  255.     xor    al,20h            ; Make it upper case
  256. gcmp_l2:
  257.     jcxz    gcmp_l1            ; Don't store if ID is full
  258.     mov    [di],al            ; Save the byte
  259.     inc    di            ; Point to next spot
  260.     dec    cx            ; Knock off the count
  261.     jmp    gcmp_l1            ; Loop back
  262. gcmp_l3:
  263.     call    skip_spaces        ; Skip any other whitespace
  264.     sub    bl,bl            ; Clear accumulator
  265. gcmp_l4:
  266.     lods    byte ptr es:[si]    ; Pick up a byte
  267.     cmp    al,'0'            ; Valid digit?
  268.     jb    gcmp_l5            ; Nope - stop now
  269.     cmp    al,'9'            ;
  270.     ja    gcmp_l5            ;
  271.     sub    al,'0'            ; Make digit binary
  272.     mov    bh,bl            ; Multiply current value by 10
  273.     shl    bh,1            ;  by (BL * 2) + (BL * 8)
  274.     shl    bl,1            ;
  275.     shl    bl,1            ;
  276.     shl    bl,1            ;
  277.     add    bl,al            ; Add in new digit
  278.     jmp    short gcmp_l4        ; Loop back
  279. gcmp_l5:
  280.     cmp    bl,12            ; Make sure it's legal
  281.     ja    gcmp_exit        ;
  282.     mov    disk_num,bl        ; Save the number
  283. gcmp_exit:
  284.     pop    es            ;
  285.     ret                ; Return to initialization
  286.  
  287. get_cmdline_parms    endp
  288.  
  289.  
  290. ;*****************************************************************************
  291. ;
  292. ; Skip whitespace characters at ES:SI
  293. ;
  294. ;*****************************************************************************
  295. skip_spaces    proc    near
  296.  
  297. sksp_l1:
  298.     mov    al,es:[si]        ; Get a byte
  299.     cmp    al,' '            ; Whitespace?
  300.     je    sksp_l2            ; Yep - skip it
  301.     cmp    al,9            ;
  302.     jne    sksp_exit        ; No - exit now
  303. sksp_l2:
  304.     inc    si            ; Skip this character
  305.     jmp    short sksp_l1        ; Loop back
  306. sksp_exit:
  307.     ret                ; Re